package leetcode.Y2024M5D27;

import org.junit.Test;

/**
 * 反转链表
 */
public class S206 {
    public ListNode reverseList(ListNode head) {
        ListNode cur = head;
        ListNode pre = null;
        while (cur!=null){
            ListNode tmp=cur.next;
            cur.next=pre;
            pre=cur;
            cur=tmp;
        }
        return pre;


    }

    @Test
    public void test() {
        int[] a = {1, 2, 3, 4, 5};
        ListNode head = ListNode.createListNode(a);
        ListNode listNode = reverseList(head);
        System.out.println(listNode);

    }
}
